<template>
	<div id="purchasehistory" class="purchasehistory same-change-oldstyle">
		<div class="same-head-box">
			<div class="saem-seat-box">
				<div class="saem-seat-left">
					<span>当前位置：</span>
					<el-breadcrumb separator-class="el-icon-arrow-right">
						<el-breadcrumb-item>设备中心</el-breadcrumb-item>
						<el-breadcrumb-item :to="{ path: '/devicelist' }">设备管理</el-breadcrumb-item>
						<el-breadcrumb-item>消费记录</el-breadcrumb-item>
					</el-breadcrumb>
				</div>
				<div class="saem-seat-right">
					<button class="same-search-btns same-search-export" @click="export_Excel">导出</button>
					<button class="same-search-btns same-search-export" @click="RefreshFun">刷新</button>
					<button class="same-search-btns" @click="returnBack">返回</button>
				</div>
			</div>
			<div class="same-search-box">
				<div>
					<div class="same-search-left">
						<div class="same-left-one">
							<span class="same-search-span same-search-fisrt">消费时间:</span>
							<el-date-picker style="width:140px" v-model="start_time" type="date" size="medium"
								value-format="yyyy-MM-dd" placeholder="开始时间"></el-date-picker>
							<div class="same-interval">至</div>
							<el-date-picker style="width:140px" v-model="end_time" type="date" size="medium" value-format="yyyy-MM-dd"
								placeholder="结束时间"></el-date-picker>
						</div>
						<div class="same-left-one">
							<span class="same-search-span">水卡号:</span>
							<el-input size="medium" v-model="cardNum" type="Number" placeholder="请输入水卡号" style="width: 160px;">
							</el-input>
						</div>
						<div class="same-left-one" v-if="!moveShow">
							<div class="same-left-zdshwo" :hidden="!moveBtn" @click="openMore">更多查询条件<i
									:class="[moveShow?'el-icon-arrow-up':'el-icon-arrow-down']"></i></div>

							<el-button type="primary" size="medium" @click="findJfList()">搜索</el-button>
							<el-button type="info" size="medium" @click="reset()">重置</el-button>
						</div>
					</div>
					<div class="same-search-right"></div>
				</div>
				<div>
					<div class="same-search-left  new-sear-height" ref="leftHeight">
						<div class="same-left-one">
							<span class="same-search-span">支付类型:</span>
							<el-select size="medium" v-model="type_s" placeholder="请选择" style="width: 140px;">
								<el-option v-for="item in stateoption" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</div>
						<div class="same-left-one" :class="[moveShow?'':'new-sear-opacity']">
							<div class="same-left-zdshwo" :hidden="!moveBtn" @click="openMore">收起更多查询条件<i
									:class="[moveShow?'el-icon-arrow-up':'el-icon-arrow-down']"></i></div>
							<el-button type="primary" size="medium" @click="findJfList()">搜索</el-button>
							<el-button type="info" size="medium" @click="reset()">重置</el-button>
						</div>
					</div>
					<div class="same-search-right"></div>
				</div>

			</div>
		</div>

		<div class="same-table-box">
			<h4 class="same-title-box">
				消费记录
				<div class="same-search-total" v-if="cen_sus && census_money != ''">
					(当前金额总计：
					<span style="color:#FF6565">{{ census_money|filterNumber }}</span>
					元，当前积分总计：
					<span style="color:#FF6565">{{ census_integral|filterNumber }}</span>
					积分)
				</div>
			</h4>
			<div class="table_box">

				<div class="common-table-outer">
					<el-table class="common-table" v-loading="loading" header-cell-class-name="common-table-header-cell"
						:data="tableData" stripe>
						<el-table-column align="center" prop="sale_number"  label="订单编号">
						</el-table-column>


						<el-table-column align="center"  label="水卡卡号">
							<template slot-scope="scope">
								{{ scope.row.card_number|| '——'}}
							</template>
						</el-table-column>
					

						<el-table-column align="center" label="手机号码">
							<template slot-scope="scope">
								{{  scope.row.phone|| '——'}}
							</template>
						</el-table-column>
					

						<el-table-column align="center"  label="打水量">
							<template slot-scope="scope">
								{{  scope.row.water_amount+'L'|| '——'}}
							</template>
						</el-table-column>
					

						<el-table-column align="center"  label="支付金额">
							<template slot-scope="scope">
								{{ scope.row.money|filterNumber}} {{scope.row.pay_type != 4?'元':'分'}}
							</template>
						</el-table-column>
					

						<el-table-column align="center"   label="订单类型">
							<template slot-scope="scope">
								<el-tag size="mini" type="success" v-if="scope.row.order_type == 1">线上</el-tag>
								<el-tag size="mini" type="warning" v-else>线下</el-tag>
	
							</template>
						</el-table-column>
					

						<el-table-column align="center" prop="id"  label="支付类型">
							<template slot-scope="scope">
								<span v-if="scope.row.pay_type == 1">微信</span>
								<span v-if="scope.row.pay_type == 2">实体卡</span>
								<span v-if="scope.row.pay_type == 3">电子卡</span>
								<span v-if="scope.row.pay_type == 4">积分</span>
								<span v-if="scope.row.pay_type == 5">投币</span>
							</template>
						</el-table-column>
					

						<el-table-column align="center" prop="id"  label="支付状态">
							<template slot-scope="scope">
								<span class="redColor greed_show" v-if="scope.row.pay_status == 1">已支付</span>
								<span class="redColor greed_show" v-if="scope.row.pay_status == 2">未支付</span>
								<span class="redColor" v-if="scope.row.pay_status == 3">已退款</span>
							</template>
						</el-table-column>
					

						
						<el-table-column align="center" prop="id"  label="下单时间">
							<template slot-scope="scope">
								{{ scope.row.create_time|| '——'}}
							</template>
						</el-table-column>

						
						<el-table-column align="center" prop="id"  label="退款时间">
							<template slot-scope="scope">
								{{ scope.row.refund_time|| '——'}}
							</template>
						</el-table-column>
					
					
						<template slot="empty" v-if="isLoad">
							<div class="new-no-data-show">
								<img src="../../assets/images/no-data.png" alt="">
								<div>暂无相关数据</div>
							</div>
						</template>
					</el-table>

					<div class="same-page-inShow" v-if="tableData.length > 0 && isLoad">
						<!--//  分页-->
						<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
							:current-page="currentPage" :page-sizes="sizes" :page-size="row"
							layout="total,prev, pager, next, jumper, sizes" :total="total"></el-pagination>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
	export default {
		name: 'purchasehistory',
		data: function () {
			return {
				loading: false,
				row: 15,
				sizes: [15, 30, 40, 50],
				total: 0,
				currentPage: 1,
				equipment_id: '',// 主板ID
				start_time: '',
				end_time: '',
				tableData: [], // 返回的结果集合
				type_s: '', //支付类型
				cardNum: '', //水卡卡号
				stateoption: [{
					value: '',
					label: '全部'
				}, {
					value: '1',
					label: '微信支付'
				}, {
					value: '2',
					label: '实体卡'
				}, {
					value: '3',
					label: '电子卡'
				}, {
					value: '4',
					label: '积分支付'
				}, {
					value: '5',
					label: '投币支付'
				}
				],
				userinfo: [],
				census_money: '', //合计金额...
				census_integral: '', // 合计积分
				cen_sus: 1, //合计状态
				isLoad: false,
				moveBtn: false,//是否暂时更多查询条件按钮按钮 搜索条件控制
				moveShow: false,//是否开启动画
				scrollHeight: '',//需要监听的高度
			};
		},
		computed: {},
		// 初始化执行
		created: function () {

		},
		inject: [
			'reload'
		],
		methods: {
			RefreshFun() {
				// 调用reload方法，刷新整个页面
				this.reload()
			},
			//返回
			returnBack() {
				this.$router.back(-1);
			},
			//导出...
			export_Excel() {
				var that = this;
				that.$post({
					url: 'Partner/Equipment/exportConsumption',
					data: {
						equipment_id: that.equipment_id,
						start_time: that.start_time ? that.start_time : '',
						end_time: that.end_time ? that.end_time : '',
						card: that.cardNum,
						pay_type: that.type_s,
					},
					success: data => {
						if (data.code < 0) {
							this.$message({
								showClose: true,
								message: data.data.message,
								center: true
							});
						}
						var $form = $('<form method="GET"></form>');
						$form.attr('action', data.data);
						$form.appendTo($('body'));
						$form.submit();
					}
				});
			},
			reset() {
				this.start_time = '';
				this.end_time = '';
				this.cardNum = '';
				this.type_s = '';
				this.page = 1;
				this.consumptionList();
			},

			//搜索
			findJfList() {
				this.page = 1;
				this.consumptionList();
			},
			//每页
			handleSizeChange(val) {
				this.row = val;
				this.page = 1;
				this.consumptionList();
			},
			//分页
			handleCurrentChange(val) {
				this.page = val;
				this.consumptionList();
			},
			// 获取积分管理页面数据
			consumptionList: function () {
				var that = this;
				that.loading = true; //打开loading动画
				that.isLoad = false; //是否加载

				// ajax请求
				that.$post({
					url: 'Partner/OrderList/sell_water',
					data: {
						equipment_id: that.equipment_id,
						page: that.page,
						pageSize: that.row,
						start_time: that.start_time,
						end_time: that.end_time,
						card_number: that.cardNum,
						pay_type: that.type_s,
					},
					success: data => {
						that.isLoad = true;
						that.loading = false; //关闭动画
						if (data.code == 1000) {
							that.tableData = data.data.order;
							that.total = Number(data.data.count);
							that.currentPage = that.page;
							that.census_money = data.data.sum; //合计
							that.census_integral = data.data.integral; //合计
						} else if (data.code == -1003) {
							if(that.page==1){
								that.tableData = [];
							}
							that.total = '';
							that.census_money = ''; //合计
							that.census_integral = '';//合计
						} else {
							this.$message.error(data.message);
						}
					}
				});
			},
			//此处获取高度必须在dom元素创建完成之后才能获取
			gitHeight() {
				//  let clientHeight=this.$refs.leftHeight.clientHeight;
				let scrollHeight = this.$refs.leftHeight.scrollHeight;
				this.scrollHeight = scrollHeight;
				scrollHeight <= 30 ? this.moveBtn = false : this.moveBtn = true;

			},
			openMore() {
				this.moveShow = !this.moveShow;
				this.$refs.leftHeight.style.height = this.moveShow ? this.scrollHeight + 'px' : 0 + 'px';
			},
		},
		mounted() {
			this.equipment_id = this.$route.query.equipment_id;  // 接收设备ID
			this.consumptionList(); // 获取积分管理页面数据
			this.gitHeight();
			//监听高度变化 
			var that = this;
			window.addEventListener("resize", function () {
				let scrollHeight = that.$refs.leftHeight && that.$refs.leftHeight.scrollHeight ? that.$refs.leftHeight.scrollHeight : that.scrollHeight;
				that.scrollHeight = scrollHeight;
			});
		},
		watch: {
			// 如果 `scrollHeight` 发生改变，这个函数就会运行 此处是为了防止用户缩小屏幕导致页面显示不全
			scrollHeight: function (val) {
				this.$refs.leftHeight.style.height = this.moveShow ? this.scrollHeight + 'px' : 0 + 'px';
			}
		}
	};
</script>
<style>
	#purchasehistory {
		width: 100%;
		height: 100%;
		background: #ffffff;
	}

	#purchasehistory .redColor {
		color: #FF6565;
	}

	#purchasehistory .greed_show {
		color: #399544;
	}
</style>